package com.xpqh.ksg.common.persistence.dao;

import com.xpqh.ksg.common.persistence.model.KsgUsers;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 * 用户信息表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2025-04-14
 */
public interface KsgUsersMapper extends BaseMapper<KsgUsers> {

    @Select("SELECT status FROM ksg_users WHERE phone = #{phone}")
    Integer getStatusByPhone(@Param("phone") String phone);

    @Select("SELECT user_id FROM ksg_users WHERE phone = #{phone} and password = #{password}")
    String pwdLogin(@Param("phone") String phone, @Param("password") String password);

    @Select("SELECT user_id FROM ksg_users WHERE phone = #{phone}")
    Integer getUserIdByPhone(@Param("phone")String phone);

    @Select("SELECT count(1) FROM js_sys_user WHERE login_code = #{phone} and status = 0")
    Integer isAdmin(@Param("phone")String phone);

    @Select("SELECT count(1) FROM ksg_users WHERE user_id = #{userId} and password = #{pwd} and status = 0")
    Integer validPwd(@Param("userId")int userId, @Param("pwd")String pwd);

    @Update("UPDATE ksg_users SET password = #{newPwd} WHERE user_id = #{userId}")
    void updatePwd(@Param("userId")int userId, @Param("newPwd")String newPwd);
}

